#include "BoukenAbilitySystemComponent.h"

void UBoukenAbilitySystemComponent::InitActors(AActor* InOwnerActor, AActor* InAvatarActor)
{
	InitAbilityActorInfo(InOwnerActor, InAvatarActor);
}

void UBoukenAbilitySystemComponent::AcquireAbility(TSubclassOf<UGameplayAbility> Ability, const int32 Level, const int32 InputID)
{
	if(!GetOwnerActor() || !GetOwnerActor()->HasAuthority())
		return;
	GiveAbility(FGameplayAbilitySpec(Ability, Level, InputID));
}

void UBoukenAbilitySystemComponent::GetActiveAbilitiesWithTags(const FGameplayTagContainer& GameplayTagContainer, TArray<UGameplayAbility*>& ActiveAbilities, bool bOnlyAbilitiesThatSatisfyTagRequirements)
{
	TArray<FGameplayAbilitySpec*> AbilitiesToActivate;
	GetActivatableGameplayAbilitySpecsByAllMatchingTags(GameplayTagContainer, AbilitiesToActivate, bOnlyAbilitiesThatSatisfyTagRequirements);
	for (auto Spec : AbilitiesToActivate)
	{
		auto AbilityInstances = Spec->GetAbilityInstances();
		for (UGameplayAbility* ActiveAbility : AbilityInstances)
		{
			ActiveAbilities.Add(Cast<UGameplayAbility>(ActiveAbility));
		}
	}
}
